﻿using Common;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using NursingFormSystem.NurFormsService;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NursingFormSystem.RiskAssessment
{
    public partial class RiskSoreNursing : Form
    {

        //窗体构造函数
        public static Tb_User LoginUser;
        public Tb_User InitLoginUser(string[] UserParam)
        {
            if (LoginUser == null)
            {
                LoginUser = new Tb_User();
                LoginUser.UserId = UserParam[0];
                LoginUser.UserName = UserParam[1];
                LoginUser.DepartmentCode = UserParam[2];
                LoginUser.DepartmentName = UserParam[3];
                LoginUser.JobTitle = UserParam[4];
                LoginUser.PositionTitle = UserParam[5];
            }
            return LoginUser;
        }
        private gregn6Lib.GridppReport gpr_Feport = new gregn6Lib.GridppReport();//引用对象
        //DataTable patientDt = null;
        NursingFormRecord record = new NursingFormRecord();
        //WebReference2.FunctionAndPermissions funcService = new WebReference2.FunctionAndPermissions();
        NurFormsService.NursingForm formService = new NurFormsService.NursingForm();
        string[] Patient;//选前选中患者信息，数组，传入调用的form中

        string formID = "";
        string formName = "";
        string esSwitch = Base.ESSwitch;//获取是否使用电签标识
        public RiskSoreNursing(string[] UserParam, string[] PatientInfo, string FormName, string FormID)
        {
            //页面初始化
            InitializeComponent();
            //InitLoginUser(UserParam);
            InitLoginUser(UserParam); // 调用电签
            Patient = PatientInfo; 

        }

        #region 历史记录
        //public RiskSoreNursing(string p1, int p4, DateTime date)
        //{
        //    //this.RiskSoreNursing_Load(null, null);
        //    //页面初始化
        //    InitializeComponent();
        //    // TODO: Complete member initialization
        //    this.p1 = p1;
        //    this.p4 = p4;
        //    this.date = date;

        //    var ret = formService.GetNursingFormRecord(p1, p4, (int)FormType.RiskSore);
        //    var ret = formService.GetNursingFormRecordByDate(patientDt.Rows[ddlPatient.SelectedIndex]["PATIENT_ID"].ToString(), Convert.ToInt32(patientDt.Rows[ddlPatient.SelectedIndex]["VISIT_ID"].ToString()), (int)FormType.RiskSore, dateE_AssDate.DateTime, dateE_AssDate.DateTime);
        //    if (ret.Code == 1)
        //    {
        //        List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
        //        if (list.Count > 0)
        //        {
        //            NursingFormRecord record1 = list[0];
        //            RiskSore rs = XmlUtil.XMLToObject<RiskSore>(record1.NursingFormData, Encoding.UTF8);
        //            YaChuang ps = XmlUtil.XMLToObject<YaChuang>(record1.NursingFormData, Encoding.UTF8);

        //            //var begin = dateE_AssDate.DateTime.ToString("yyyy-MM-dd 00:00:00");
        //            //var end = dateE_AssDate.DateTime.ToString("yyyy-MM-dd 23:59:59");
        //            //var ps = rs.RiskSoreList.Where(x => String.Compare(x.PingGuRiQi, begin) >= 0 && String.Compare(x.PingGuRiQi, end) <= 0).OrderByDescending(x => x.PingGuRiQi).FirstOrDefault();
        //            //if (ps != null)
        //            //{
        //            txtjiashu.Text = rs.HuanZheQianZi;//患者或家属签名
        //            txtguanxi.Text = rs.YuHuanZheGuanXi;//与患者关系
        //            txtSituation.Text = rs.HuanZhePiFuQingGuang;//皮肤情况
        //            dateE_AssDate.DateTime = Convert.ToDateTime(ps.PingGuRiQi);//评估日期
        //            //感觉
        //            if (ps.GanJue == "4")
        //                radFeel.SelectedIndex = 0;
        //            else if (ps.GanJue == "3")
        //                radFeel.SelectedIndex = 1;
        //            else if (ps.GanJue == "2")
        //                radFeel.SelectedIndex = 2;
        //            else if (ps.GanJue == "1")
        //                radFeel.SelectedIndex = 3;
        //            else
        //                radFeel.SelectedIndex = -1;
        //            //潮湿
        //            if (ps.ChaoShi == "4")
        //                radDamp.SelectedIndex = 0;
        //            else if (ps.ChaoShi == "3")
        //                radDamp.SelectedIndex = 1;
        //            else if (ps.ChaoShi == "2")
        //                radDamp.SelectedIndex = 2;
        //            else if (ps.ChaoShi == "1")
        //                radDamp.SelectedIndex = 3;
        //            else
        //                radDamp.SelectedIndex = -1;
        //            //活动力
        //            if (ps.HuoDongLi == "4")
        //                radActivity.SelectedIndex = 0;
        //            else if (ps.HuoDongLi == "3")
        //                radActivity.SelectedIndex = 1;
        //            else if (ps.HuoDongLi == "2")
        //                radActivity.SelectedIndex = 2;
        //            else if (ps.HuoDongLi == "1")
        //                radActivity.SelectedIndex = 3;
        //            else
        //                radActivity.SelectedIndex = -1;
        //            //移动力
        //            if (ps.YiDongLi == "4")
        //                radMove.SelectedIndex = 0;
        //            else if (ps.YiDongLi == "3")
        //                radMove.SelectedIndex = 1;
        //            else if (ps.YiDongLi == "2")
        //                radMove.SelectedIndex = 2;
        //            else if (ps.YiDongLi == "1")
        //                radMove.SelectedIndex = 3;
        //            else
        //                radMove.SelectedIndex = -1;
        //            //摩擦力和剪切力
        //            if (ps.MoChaLiHeJianQieLi == "3")
        //                radFriction.SelectedIndex = 0;
        //            else if (ps.MoChaLiHeJianQieLi == "2")
        //                radFriction.SelectedIndex = 1;
        //            else if (ps.MoChaLiHeJianQieLi == "1")
        //                radFriction.SelectedIndex = 2;
        //            else
        //                radFriction.SelectedIndex = -1;
        //            //营养
        //            if (ps.YingYang == "4")
        //                radNutrition.SelectedIndex = 0;
        //            else if (ps.YingYang == "3")
        //                radNutrition.SelectedIndex = 1;
        //            else if (ps.YingYang == "2")
        //                radNutrition.SelectedIndex = 2;
        //            else if (ps.YingYang == "1")
        //                radNutrition.SelectedIndex = 3;
        //            else
        //                radNutrition.SelectedIndex = -1;
        //            //体位安置与变换
        //            var PosturalPlacement = ps.TiWeiAnZhiYuBianHuan.Split('#');
        //            if (PosturalPlacement[0] == "1")
        //                cheTiwei1.Checked = true;
        //            else
        //                cheTiwei1.Checked = false;
        //            if (PosturalPlacement[1] == "1")
        //                cheTiwei2.Checked = true;
        //            else
        //                cheTiwei2.Checked = false;
        //            if (PosturalPlacement[2] == "1")
        //                cheTiwei3.Checked = true;
        //            else
        //                cheTiwei3.Checked = false;
        //            if (PosturalPlacement[3] == "1")
        //                cheTiwei4.Checked = true;
        //            else
        //                cheTiwei4.Checked = false;
        //            if (PosturalPlacement[4] == "1")
        //                cheTiwei5.Checked = true;
        //            else
        //                cheTiwei5.Checked = false;
        //            if (PosturalPlacement[5] == "1")
        //                cheTiwei6.Checked = true;
        //            else
        //                cheTiwei6.Checked = false;
        //            //减压用具与使用
        //            var Decompression = ps.JianYaYongJuYuShiYong.Split('#');
        //            if (Decompression[0] == "1")
        //                cheJianya1.Checked = true;
        //            else
        //                cheJianya1.Checked = false;
        //            if (Decompression[1] == "1")
        //                cheJianya2.Checked = true;
        //            else
        //                cheJianya2.Checked = false;
        //            if (Decompression[2] == "1")
        //                cheJianya3.Checked = true;
        //            else
        //                cheJianya3.Checked = false;
        //            if (Decompression[3] == "1")
        //                cheJianya4.Checked = true;
        //            else
        //                cheJianya4.Checked = false;
        //            //皮肤护理
        //            var SkinCare = ps.PiFuHuLi.Split('#');
        //            if (SkinCare[0] == "1")
        //                chePifu1.Checked = true;
        //            else
        //                chePifu1.Checked = false;
        //            if (SkinCare[1] == "1")
        //                chePifu2.Checked = true;
        //            else
        //                chePifu2.Checked = false;
        //            if (SkinCare[2] == "1")
        //                chePifu3.Checked = true;
        //            else
        //                chePifu3.Checked = false;
        //            if (SkinCare[3] == "1")
        //                chePifu4.Checked = true;
        //            else
        //                chePifu4.Checked = false;
        //            if (SkinCare[4] == "1")
        //                chePifu5.Checked = true;
        //            else
        //                chePifu5.Checked = false;
        //            if (SkinCare[5] == "1")
        //                chePifu6.Checked = true;
        //            else
        //                chePifu6.Checked = false;
        //            //营养支持
        //            var NutritionSupport = ps.YingYangZhiChi.Split('#');
        //            if (NutritionSupport[0] == "1")
        //                cheYingyang1.Checked = true;
        //            else
        //                cheYingyang1.Checked = false;
        //            if (NutritionSupport[1] == "1")
        //                cheYingyang2.Checked = true;
        //            else
        //                cheYingyang2.Checked = false;
        //            if (NutritionSupport[2] == "1")
        //                cheYingyang3.Checked = true;
        //            else
        //                cheYingyang3.Checked = false;
        //            if (NutritionSupport[3] == "1")
        //                cheYingyang4.Checked = true;
        //            else
        //                cheYingyang4.Checked = false;

        //            txtNurse.Text = ps.HuShiQianMing;//护士签字
        //            txtNurseZ.Text = ps.HuShiZhangQianMing;//护士长签字
        //            //预后
        //            var Prognosis = rs.YuHou.Split('#');
        //            if (Prognosis[0] == "1")
        //                cheYuhou1.Checked = true;
        //            else
        //                cheYuhou1.Checked = false;
        //            if (Prognosis[1] == "1")
        //                cheYuhou2.Checked = true;
        //            else
        //                cheYuhou2.Checked = false;
        //            if (Prognosis[2] == "1")
        //                cheYuhou3.Checked = true;
        //            else
        //                cheYuhou3.Checked = false;
        //            if (Prognosis[3] == "1")
        //                cheYuhou4.Checked = true;
        //            else
        //                cheYuhou4.Checked = false;
        //            if (Prognosis[4] == "1")
        //                cheYuhou5.Checked = true;
        //            else
        //                cheYuhou5.Checked = false;
        //            if (Prognosis[5] == "1")
        //                cheYuhou6.Checked = true;
        //            else
        //                cheYuhou6.Checked = false;
        //            txtScoreTotal.Text = ps.ZongFen.ToString();//总分
        //        }
        //    }
        //    else if (ret.Code == 0)
        //    {
        //        MessageBox.Show(ret.M);
        //    }
        //}
        #endregion

        //计算分值
        #region
        private void RiskSoreNursing_Load(object sender, EventArgs e)
        {
            dateE_AssDate.DateTime = DateTime.Now;
        }
        private void radFeel_SelectedIndexChanged(object sender, EventArgs e)
        {
            SunTotal();
        }

        private void radDamp_SelectedIndexChanged(object sender, EventArgs e)
        {
            SunTotal();
        }

        private void radActivity_SelectedIndexChanged(object sender, EventArgs e)
        {
            SunTotal();
        }

        private void radMove_SelectedIndexChanged(object sender, EventArgs e)
        {
            SunTotal();
        }

        private void radFriction_SelectedIndexChanged(object sender, EventArgs e)
        {
            SunTotal();
        }

        private void radNutrition_SelectedIndexChanged(object sender, EventArgs e)
        {
            SunTotal();
        }
        #endregion
        public void SunTotal()
        {
            int Sum = 0;
            int Total = 0;
            int Total1 = 0;
            int Total2 = 0;
            int Total3 = 0;
            int Total4 = 0;
            int Total5 = 0;
            //感觉
            if (radFeel.SelectedIndex == 0)
                Total = 4;
            else if (radFeel.SelectedIndex == 1)
                Total = 3;
            else if (radFeel.SelectedIndex == 2)
                Total = 2;
            else if (radFeel.SelectedIndex == 3)
                Total = 1;
            else
                Total = 0;
            //潮湿
            if (radDamp.SelectedIndex == 0)
                Total1 = 4;
            else if (radDamp.SelectedIndex == 1)
                Total1 = 3;
            else if (radDamp.SelectedIndex == 2)
                Total1 = 2;
            else if (radDamp.SelectedIndex == 3)
                Total1 = 1;
            else
                Total1 = 0;
            //活动力
            if (radActivity.SelectedIndex == 0)
                Total2 = 4;
            else if (radActivity.SelectedIndex == 1)
                Total2 = 3;
            else if (radActivity.SelectedIndex == 2)
                Total2 = 2;
            else if (radActivity.SelectedIndex == 3)
                Total2 = 1;
            else
                Total2 = 0;
            //移动力
            if (radMove.SelectedIndex == 0)
                Total3 = 4;
            else if (radMove.SelectedIndex == 1)
                Total3 = 3;
            else if (radMove.SelectedIndex == 2)
                Total3 = 2;
            else if (radMove.SelectedIndex == 3)
                Total3 = 1;
            else
                Total3 = 0;
            //摩擦力和剪切力
            if (radFriction.SelectedIndex == 0)
                Total4 = 3;
            else if (radFriction.SelectedIndex == 1)
                Total4 = 2;
            else if (radFriction.SelectedIndex == 2)
                Total4 = 1;
            else
                Total4 = 0;
            //营养
            if (radNutrition.SelectedIndex == 0)
                Total5 = 4;
            else if (radNutrition.SelectedIndex == 1)
                Total5 = 3;
            else if (radNutrition.SelectedIndex == 2)
                Total5 = 2;
            else if (radNutrition.SelectedIndex == 3)
                Total5 = 1;
            else
                Total5 = 0;

            Sum = Total + Total1 + Total2 + Total3 + Total4 + Total5;
            txtScoreTotal.Text = Sum.ToString();
        }

        private void dateE_AssDate_EditValueChanged(object sender, EventArgs e)
        {
            str();
        }

        private void btn_Query_Click(object sender, EventArgs e)
        {
            str();
        }
        //显示
        public void str()
        {
            //if (ddlPatient.SelectedIndex == -1)
            //{
            //    MessageBox.Show("请选择患者！");
            //    return;
            //}
            var ret = formService.GetNursingFormRecordByDate(Patient[0], Convert.ToInt32(Patient[1]), (int)FormType.RiskSore, dateE_AssDate.DateTime, dateE_AssDate.DateTime);
            if (ret.Code == 1)
            {
                List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
                if (list.Count > 0)
                {
                    NursingFormRecord record1 = list[0];
                    RiskSore ps = XmlUtil.XMLToObject<RiskSore>(record1.NursingFormData, Encoding.UTF8);

                    //NursingFormRecord record1 = ret.D;
                    //RiskSore rs = XmlUtil.XMLToObject<RiskSore>(record1.NursingFormData, Encoding.UTF8);

                    //var begin = dateE_AssDate.DateTime.ToString("yyyy-MM-dd 00:00:00");
                    //var end = dateE_AssDate.DateTime.ToString("yyyy-MM-dd 23:59:59");
                    //var ps = rs.RiskSoreList.Where(x => String.Compare(x.PingGuRiQi, begin) >= 0 && String.Compare(x.PingGuRiQi, end) <= 0).OrderByDescending(x => x.PingGuRiQi).FirstOrDefault();
                    //if (ps != null)
                    //{
                    txtjiashu.Text = ps.HuanZheQianZi;//患者或家属签名
                    txtguanxi.Text = ps.YuHuanZheGuanXi;//与患者关系
                    txtSituation.Text = ps.HuanZhePiFuQingGuang;//皮肤情况
                    dateE_AssDate.DateTime = Convert.ToDateTime(ps.PingGuRiQi.ToString());//评估日期
                    //感觉
                    if (ps.GanJue == "4")
                        radFeel.SelectedIndex = 0;
                    else if (ps.GanJue == "3")
                        radFeel.SelectedIndex = 1;
                    else if (ps.GanJue == "2")
                        radFeel.SelectedIndex = 2;
                    else if (ps.GanJue == "1")
                        radFeel.SelectedIndex = 3;
                    else
                        radFeel.SelectedIndex = -1;
                    //潮湿
                    if (ps.ChaoShi == "4")
                        radDamp.SelectedIndex = 0;
                    else if (ps.ChaoShi == "3")
                        radDamp.SelectedIndex = 1;
                    else if (ps.ChaoShi == "2")
                        radDamp.SelectedIndex = 2;
                    else if (ps.ChaoShi == "1")
                        radDamp.SelectedIndex = 3;
                    else
                        radDamp.SelectedIndex = -1;
                    //活动力
                    if (ps.HuoDongLi == "4")
                        radActivity.SelectedIndex = 0;
                    else if (ps.HuoDongLi == "3")
                        radActivity.SelectedIndex = 1;
                    else if (ps.HuoDongLi == "2")
                        radActivity.SelectedIndex = 2;
                    else if (ps.HuoDongLi == "1")
                        radActivity.SelectedIndex = 3;
                    else
                        radActivity.SelectedIndex = -1;
                    //移动力
                    if (ps.YiDongLi == "4")
                        radMove.SelectedIndex = 0;
                    else if (ps.YiDongLi == "3")
                        radMove.SelectedIndex = 1;
                    else if (ps.YiDongLi == "2")
                        radMove.SelectedIndex = 2;
                    else if (ps.YiDongLi == "1")
                        radMove.SelectedIndex = 3;
                    else
                        radMove.SelectedIndex = -1;
                    //摩擦力和剪切力
                    if (ps.MoChaLiHeJianQieLi == "3")
                        radFriction.SelectedIndex = 0;
                    else if (ps.MoChaLiHeJianQieLi == "2")
                        radFriction.SelectedIndex = 1;
                    else if (ps.MoChaLiHeJianQieLi == "1")
                        radFriction.SelectedIndex = 2;
                    else
                        radFriction.SelectedIndex = -1;
                    //营养
                    if (ps.YingYang == "4")
                        radNutrition.SelectedIndex = 0;
                    else if (ps.YingYang == "3")
                        radNutrition.SelectedIndex = 1;
                    else if (ps.YingYang == "2")
                        radNutrition.SelectedIndex = 2;
                    else if (ps.YingYang == "1")
                        radNutrition.SelectedIndex = 3;
                    else
                        radNutrition.SelectedIndex = -1;
                    //体位安置与变换
                    var PosturalPlacement = ps.TiWeiAnZhiYuBianHuan.Split('#');
                    if (PosturalPlacement[0] == "1")
                        cheTiwei1.Checked = true;
                    else
                        cheTiwei1.Checked = false;
                    if (PosturalPlacement[1] == "1")
                        cheTiwei2.Checked = true;
                    else
                        cheTiwei2.Checked = false;
                    if (PosturalPlacement[2] == "1")
                        cheTiwei3.Checked = true;
                    else
                        cheTiwei3.Checked = false;
                    if (PosturalPlacement[3] == "1")
                        cheTiwei4.Checked = true;
                    else
                        cheTiwei4.Checked = false;
                    if (PosturalPlacement[4] == "1")
                        cheTiwei5.Checked = true;
                    else
                        cheTiwei5.Checked = false;
                    if (PosturalPlacement[5] == "1")
                        cheTiwei6.Checked = true;
                    else
                        cheTiwei6.Checked = false;
                    //减压用具与使用
                    var Decompression = ps.JianYaYongJuYuShiYong.Split('#');
                    if (Decompression[0] == "1")
                        cheJianya1.Checked = true;
                    else
                        cheJianya1.Checked = false;
                    if (Decompression[1] == "1")
                        cheJianya2.Checked = true;
                    else
                        cheJianya2.Checked = false;
                    if (Decompression[2] == "1")
                        cheJianya3.Checked = true;
                    else
                        cheJianya3.Checked = false;
                    if (Decompression[3] == "1")
                        cheJianya4.Checked = true;
                    else
                        cheJianya4.Checked = false;
                    //皮肤护理
                    var SkinCare = ps.PiFuHuLi.Split('#');
                    if (SkinCare[0] == "1")
                        chePifu1.Checked = true;
                    else
                        chePifu1.Checked = false;
                    if (SkinCare[1] == "1")
                        chePifu2.Checked = true;
                    else
                        chePifu2.Checked = false;
                    if (SkinCare[2] == "1")
                        chePifu3.Checked = true;
                    else
                        chePifu3.Checked = false;
                    if (SkinCare[3] == "1")
                        chePifu4.Checked = true;
                    else
                        chePifu4.Checked = false;
                    if (SkinCare[4] == "1")
                        chePifu5.Checked = true;
                    else
                        chePifu5.Checked = false;
                    if (SkinCare[5] == "1")
                        chePifu6.Checked = true;
                    else
                        chePifu6.Checked = false;
                    //营养支持
                    var NutritionSupport = ps.YingYangZhiChi.Split('#');
                    if (NutritionSupport[0] == "1")
                        cheYingyang1.Checked = true;
                    else
                        cheYingyang1.Checked = false;
                    if (NutritionSupport[1] == "1")
                        cheYingyang2.Checked = true;
                    else
                        cheYingyang2.Checked = false;
                    if (NutritionSupport[2] == "1")
                        cheYingyang3.Checked = true;
                    else
                        cheYingyang3.Checked = false;
                    if (NutritionSupport[3] == "1")
                        cheYingyang4.Checked = true;
                    else
                        cheYingyang4.Checked = false;

                    txtNurse.Text = ps.HuShiQianMing;//护士签字
                    txtNurseZ.Text = ps.HuShiZhangQianMing;//护士长签字
                    //预后
                    var Prognosis = ps.YuHou.Split('#');
                    if (Prognosis[0] == "1")
                        cheYuhou1.Checked = true;
                    else
                        cheYuhou1.Checked = false;
                    if (Prognosis[1] == "1")
                        cheYuhou2.Checked = true;
                    else
                        cheYuhou2.Checked = false;
                    if (Prognosis[2] == "1")
                        cheYuhou3.Checked = true;
                    else
                        cheYuhou3.Checked = false;
                    if (Prognosis[3] == "1")
                        cheYuhou4.Checked = true;
                    else
                        cheYuhou4.Checked = false;
                    if (Prognosis[4] == "1")
                        cheYuhou5.Checked = true;
                    else
                        cheYuhou5.Checked = false;
                    if (Prognosis[5] == "1")
                        cheYuhou6.Checked = true;
                    else
                        cheYuhou6.Checked = false;
                    txtScoreTotal.Text = ps.ZongFen.ToString();//总分
                    //}
                }
            }
            else if (ret.Code == 0)
            {
                MessageBox.Show(ret.M);
            }
            else if (ret.Code == 2)
            {
                //感觉
                radFeel.SelectedIndex = -1;
                //潮湿
                radDamp.SelectedIndex = -1;
                //活动力
                radActivity.SelectedIndex = -1;
                //移动力
                radMove.SelectedIndex = -1;
                //摩擦力和剪切力
                radFriction.SelectedIndex = -1;
                //营养
                radNutrition.SelectedIndex = -1;
                //体位安置与变换
                cheTiwei1.Checked = false;
                cheTiwei2.Checked = false;
                cheTiwei3.Checked = false;
                cheTiwei4.Checked = false;
                cheTiwei5.Checked = false;
                cheTiwei6.Checked = false;
                //减压用具与使用
                cheJianya1.Checked = false;
                cheJianya2.Checked = false;
                cheJianya3.Checked = false;
                cheJianya4.Checked = false;
                //皮肤护理
                chePifu1.Checked = false;
                chePifu2.Checked = false;
                chePifu3.Checked = false;
                chePifu4.Checked = false;
                chePifu5.Checked = false;
                chePifu6.Checked = false;
                //营养支持
                cheYingyang1.Checked = false;
                cheYingyang2.Checked = false;
                cheYingyang3.Checked = false;
                cheYingyang4.Checked = false;
                //护士签字
                txtNurse.Text = "";
                //护士长签字
                txtNurseZ.Text = "";
                //预后
                cheYuhou1.Checked = false;
                cheYuhou2.Checked = false;
                cheYuhou3.Checked = false;
                cheYuhou4.Checked = false;
                cheYuhou5.Checked = false;
                cheYuhou6.Checked = false;
                //患者或家属签名
                txtjiashu.Text = "";
                //与患者关系
                txtguanxi.Text = "";
                //皮肤情况
                txtSituation.Text = "";
                //总分
                txtScoreTotal.Text = "";
            }
        }
        //保存
        private void btn_Preservation_Click(object sender, EventArgs e)
        {
            
            var ret = formService.GetNursingFormRecord(Patient[0], Convert.ToInt32(Patient[1]), (int)FormType.RiskSore);
            RiskSore rs = new RiskSore()
            {
                FormId = (int)FormType.RiskSore,//表单ID
                FormName = EnumHelper.GetDescription(FormType.RiskSore),//表单Name
                YuHou = (cheYuhou1.Checked == true ? "1" : "0") + "#" + (cheYuhou2.Checked == true ? "1" : "0") + "#" + (cheYuhou3.Checked == true ? "1" : "0") + "#" + (cheYuhou4.Checked == true ? "1" : "0") + "#" + (cheYuhou5.Checked == true ? "1" : "0") + "#" + (cheYuhou6.Checked == true ? "1" : "0"),//预后
                HuanZheQianZi = txtjiashu.Text,//患者/家属签字
                YuHuanZheGuanXi = txtguanxi.Text,//与患者关系
                HuanZhePiFuQingGuang = txtSituation.Text,//患者皮肤情况
                PingGuRiQi = dateE_AssDate.DateTime.ToString(),//评估日期
                GanJue = radFeel.EditValue == null ? "" : radFeel.EditValue.ToString(),//感觉
                ChaoShi = radDamp.EditValue == null ? "" : radDamp.EditValue.ToString(),//潮湿
                HuoDongLi = radActivity.EditValue == null ? "" : radActivity.EditValue.ToString(),//活动力
                YiDongLi = radMove.EditValue == null ? "" : radMove.EditValue.ToString(),//移动力
                MoChaLiHeJianQieLi = radFriction.EditValue == null ? "" : radFriction.EditValue.ToString(),//摩擦力和剪切力
                YingYang = radNutrition.EditValue == null ? "" : radNutrition.EditValue.ToString(),//营养
                TiWeiAnZhiYuBianHuan = (cheTiwei1.Checked == true ? "1" : "0") + "#" + (cheTiwei2.Checked == true ? "1" : "0") + "#" + (cheTiwei3.Checked == true ? "1" : "0") + "#" + (cheTiwei4.Checked == true ? "1" : "0") + "#" + (cheTiwei5.Checked == true ? "1" : "0") + "#" + (cheTiwei6.Checked == true ? "1" : "0"),//体位安置与变换
                JianYaYongJuYuShiYong = (cheJianya1.Checked == true ? "1" : "0") + "#" + (cheJianya2.Checked == true ? "1" : "0") + "#" + (cheJianya3.Checked == true ? "1" : "0") + "#" + (cheJianya4.Checked == true ? "1" : "0"),//减压用具与使用
                PiFuHuLi = (chePifu1.Checked == true ? "1" : "0") + "#" + (chePifu2.Checked == true ? "1" : "0") + "#" + (chePifu3.Checked == true ? "1" : "0") + "#" + (chePifu4.Checked == true ? "1" : "0") + "#" + (chePifu5.Checked == true ? "1" : "0") + "#" + (chePifu6.Checked == true ? "1" : "0"),//皮肤护理
                YingYangZhiChi = (cheYingyang1.Checked == true ? "1" : "0") + "#" + (cheYingyang2.Checked == true ? "1" : "0") + "#" + (cheYingyang3.Checked == true ? "1" : "0") + "#" + (cheYingyang4.Checked == true ? "1" : "0"),//营养支持
                HuShiQianMing = txtNurse.Text,//护士签字
                HuShiZhangQianMing = txtNurseZ.Text,//护士长签字
                ZongFen = txtScoreTotal.Text//总分
            };
           
            record.NursingFormData = XmlUtil.ObjectToXML(rs, Encoding.UTF8);
            record.FormId = (int)FormType.RiskSore;//表单ID
            record.FormName = EnumHelper.GetDescription(FormType.RiskSore);//表单Name
            record.PatientId = Patient[0];//住院号
            record.VisitId = Convert.ToInt32(Patient[1]);//住院次数
            record.PatientName = Patient[2];//住院名称
            record.BedNo = Patient[5];//床号
            record.DepartmentId = Patient[8];//病区号
            record.DepartmentName = Patient[9];//病区名称
            record.AreaId = Patient[10];//所在地编号
            record.AreaName = Patient[11];//所在地名称
            record.AssessmentDate = dateE_AssDate.DateTime;//评估日期

            var ret1 = formService.SetNursingFormRecord(Newtonsoft.Json.JsonConvert.SerializeObject(record));
            if (ret1.S == true)
            {
                //MessageBox.Show(ret1.M);
                //保存字段拼接成xml格式
                string signXml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><pingguriqi name=\"评估日期\">" + dateE_AssDate.Text + "</pingguriqi><zongfen name=\"总分\">" + txtScoreTotal.Text + "</zongfen><ganjue name=\"感觉\">" + radFeel.Text + "</ganjue>"
                    + "<chaoshi name=\"潮湿\">" + radDamp.Text + "</chaoshi><huodongli name=\"活动力\">" + radActivity.Text + "</huodongli><yidongli name=\"移动力\">" + radMove.Text + "</yidongli><friction name=\"摩擦力和剪切力\">" + radFriction.Text + "</friction>"
                    + "<yingyang name=\"营养\">" + radNutrition.Text + "</yingyang><tiwei name=\"体位安置与变换\">" + (cheTiwei1.Checked == true ? "1" : "0") + "#" + (cheTiwei2.Checked == true ? "1" : "0") + "#" + (cheTiwei3.Checked == true ? "1" : "0") + "#" + (cheTiwei4.Checked == true ? "1" : "0") + "#" + (cheTiwei5.Checked == true ? "1" : "0") + "#" + (cheTiwei6.Checked == true ? "1" : "0") + "</tiwei>"
                    + "<jianya name=\"减压用具与使用\">" + (cheJianya1.Checked == true ? "1" : "0") + "#" + (cheJianya2.Checked == true ? "1" : "0") + "#" + (cheJianya3.Checked == true ? "1" : "0") + "#" + (cheJianya4.Checked == true ? "1" : "0") + "</jianya>"
                    + "<pifu name=\"皮肤护理\">" + (chePifu1.Checked == true ? "1" : "0") + "#" + (chePifu2.Checked == true ? "1" : "0") + "#" + (chePifu3.Checked == true ? "1" : "0") + "#" + (chePifu4.Checked == true ? "1" : "0") + "#" + (chePifu5.Checked == true ? "1" : "0") + "#" + (chePifu6.Checked == true ? "1" : "0") + "</pifu>"
                    + "<yingyangzhichi name=\"营养支持\">" + (cheYingyang1.Checked == true ? "1" : "0") + "#" + (cheYingyang2.Checked == true ? "1" : "0") + "#" + (cheYingyang3.Checked == true ? "1" : "0") + "#" + (cheYingyang4.Checked == true ? "1" : "0") + "</yingyangzhichi>"
                    + "<hushiqianming name=\"护士签名\">" + txtNurse.Text + "</hushiqianming><hushizhangqianming name=\"护士长签名\">" + txtNurseZ.Text + "</hushizhangqianming>"
                    + "<yuhou name=\"预后\">" + (cheYuhou1.Checked == true ? "1" : "0") + "#" + (cheYuhou2.Checked == true ? "1" : "0") + "#" + (cheYuhou3.Checked == true ? "1" : "0") + "#" + (cheYuhou4.Checked == true ? "1" : "0") + "#" + (cheYuhou5.Checked == true ? "1" : "0") + "#" + (cheYuhou6.Checked == true ? "1" : "0") + "</yuhou>"
                    + "<jiashuqianming name=\"患者/家属签字\">" + txtjiashu.Text + "</jiashuqianming><yuhuanzheguanxi name=\"与患者关系\">" + txtguanxi.Text + "</yuhuanzheguanxi><huanzhepifuqingkuang name=\"患者皮肤情况\">" + txtSituation.Text + "</huanzhepifuqingkuang>";

                //string extraInfo = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root><sign_sys>业务系统名称</sign_sys><title>单据名称</title><patient_id>病人ID</patient_id><patient_name>病人姓名</patient_name><emr_id>电子病历ID</emr_id><emr_catalog>电子病历类型</emr_catalog><his_id>HIS ID</his_id><event_no>住院号或门诊号</event_no><visit_number>住院次数，0次为门诊病人</visit_number><dept_name>科室名称</dept_name><prescribe_number>医嘱号或门诊号</prescribe_number><prescribe_sub_number>医嘱子序号或门诊子序号</prescribe_sub_number><prescribe_operation>医嘱操作（发送、校对、停止、作废）或门诊处方操作（发送）</prescribe_operation><radiotherapy_id>放疗号</radiotherapy_id><process_name>CT定位申请单审核</process_name><process_time>CT定位申请单审核时间</process_time><extend_value_1>备用扩展1</extend_value_1><extend_value_2>备用扩展2</extend_value_2><extend_value_3>备用扩展3</extend_value_3><extend_value_4>备用扩展4</extend_value_4><extend_value_5>备用扩展5</extend_value_5><extend_value_6>备用扩展6</extend_value_6><extend_value_7>备用扩展7</extend_value_7><extend_value_8>备用扩展8</extend_value_8><extend_value_9>备用扩展9</extend_value_9></root>";
                //ElectronicSignature es = new ElectronicSignature(LoginUser);
                //es.GetElectronicSignatureImage(es, signXml, extraInfo, formID, formName, Patient[0], int.Parse(Patient[1]));
                MessageBox.Show(ret1.M);
            }
            else
            {
                MessageBox.Show(ret1.M);
            }

           
            //s.GetElectronicSignatureImage(s, SignXml, extraInfo, formID, formName, patientinfo[0], int.Parse(patientinfo[1]));
            //string signData;
            //string certData;
            //string message;
            //s.GetSign("101.132.67.155:8080", "350322199505194310", SignXml, extraInfo, out signData, out certData, out message);
            //s.VilidSign("101.132.67.155:8080", signData, certData, extraInfo, out message);
        }

        private void btn_Printing_Click(object sender, EventArgs e)
        {
            //if (ddlPatient.SelectedIndex == -1)
            //{
            //    MessageBox.Show("没有要打印的条目哦");
            //    return;
            //}

            //string[] ID = new string[Convert.ToInt32(patientDt.Rows[iValue]["PATIENT_ID"].ToString())];
            //string[] ID = new string[ddlPatient.SelectedIndex];
            //for (int i = 0; i < bandedGridView1.RowCount; i++)
            //{
            //    ID[i] = bandedGridView1.GetDataRow(i)["ID"].ToString();
            //}
            //var ret = webserver2.GetPressureSore(patientDt.Rows[iValue]["PATIENT_ID"].ToString(), Convert.ToInt32(patientDt.Rows[iValue]["VISIT_ID"].ToString()), dateE_AssDate.DateTime);
            //List<T_PressureSore> psList = ret.D.ToList();
            //var ps = psList[0];
            RiskPrint xx = new RiskPrint(Patient[0], Convert.ToInt32(Patient[1]), (int)FormType.RiskSore, dateE_AssDate.DateTime);
            xx.ShowDialog();
        }  

        private void btn_History_Click(object sender, EventArgs e)
        {

           // HistoryRiskSoreNursing AddForm = new HistoryRiskSoreNursing(Patient);

           // AddForm.ShowDialog();
            //if (ddlPatient.SelectedIndex == -1)
            //{
            //    MessageBox.Show("请选择患者！");
            //    return;
            //}
            //History aa = new History(patientDt.Rows[ddlPatient.SelectedIndex]["PATIENT_ID"].ToString(), patientDt.Rows[ddlPatient.SelectedIndex]["PATIENT_NAME"].ToString() + "   " + patientDt.Rows[ddlPatient.SelectedIndex]["BED_NO"].ToString(), patientDt.Rows[ddlPatient.SelectedIndex]["VISIT_ID"].ToString(), dateE_AssDate.DateTime, Convert.ToInt32(patientDt.Rows[ddlPatient.SelectedIndex]["VISIT_ID"].ToString()));
            //aa.ShowDialog();
            //if (aa.DialogResult == DialogResult.OK)
            //{
            //    //this.refresh();
            //    //((RiskSoreNursing)this.Owner).refresh();
            //}
        }

        private void xtraScrollableControl1_Click(object sender, EventArgs e)
        {

        }

        //新增
        private void simpleButton1_Click(object sender, EventArgs e)
        {

        }
    }
}
